var $toast = {};
$toast.stopBodyScroll = function(isFixed, that) {
	var bodyEl = document.body;
	if (isFixed) { //开启
		that._top = window.scrollY;
		bodyEl.style.position = 'fixed';
		bodyEl.style.top = -that._top + 'px';
	} else { //关闭
		bodyEl.style.position = 'relative';
		bodyEl.style.top = '';
		window.scrollTo(0, that._top); // 回到原先的top
	}
};
/**
 *  param
 *  
 *  text : '内容'
 *  
 *  time : '几秒后消失'（单位毫秒） 默认1500 传0则不消失
 * 
 * */

$toast.show = function(param) {
  var text = param ? param.text || '' : ''
  var time = param ? param.time : 1500
	this.toastMask = document.getElementById("toast-mask");
	this.stopBodyScroll(true, this);
	if (this.toastMask) {
		var dom = document.getElementById("toast-text");
		dom.innerHTML = text
		this.toastMask.style.display = "block";
	} else {
		this.toast = document.createElement("div");
    this.toast.innerHTML = '<div id="toast-mask"><div class="toastMask"><div id="toast-text" class="toastText">'+ text +'</div></div></div>'
		document.body.appendChild(this.toast);
	};
  if(time !== 0) {
    var timer = setTimeout(function() {
      clearTimeout(timer)
      $toast.hide()
    },time || 1500);
  }
};
$toast.hide = function() {
	this.stopBodyScroll(false, this);
	try {
		this.toastMask = document.getElementById("toast-mask");
		this.toastMask.style.display = "none";
	} catch (e) {};
};
